home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
WINPROGS
/
UPC12BS1.ZIP
/
LIB
/
HOSTABLE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-21
|
28KB
|
701 lines
/*--------------------------------------------------------------------*/
/* h o s t a b l e . c */
/* */
/* Remote host table routines for UUPC/extended */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* Changes Copyright (c) 1990-1993 by Kendra Electronic */
/* Wonderworks. */
/* */
/* All rights reserved except those explicitly granted by the */
/* UUPC/extended license agreement. */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* RCS Information */
/*--------------------------------------------------------------------*/
/*
* $Id: hostable.c 1.7 1993/06/21 02:17:31 ahd Exp $
*
* $Log: hostable.c $
* Revision 1.7 1993/06/21 02:17:31 ahd
* Correct errors in mail routing via HOSTPATH
*
* Revision 1.6 1993/05/29 15:19:59 ahd
* Allow configured systems, passwd files
*
* Revision 1.5 1993/04/11 00:32:29 ahd
* Global edits for year, TEXT, etc.
*
* Revision 1.4 1993/04/04 04:57:01 ahd
* Trap existence of local host name in SYSTEMS file
*
* Revision 1.3 1992/12/18 12:05:57 ahd
* Suppress duplicate machine state messages to improving OS/2 scrolling
*
* Revision 1.3 1992/12/18 12:05:57 ahd
* Suppress duplicate machine state messages to improving OS/2 scrolling
*
* Revision 1.2 1992/11/22 20:58:55 ahd
* Use strpool to allocate const strings
*
* 18 Mar 1990 Create hostable.c from router.c ahd
* Move code to generate localdomain to here ahd
* 22 Apr 90 Perform check for full host name before examining
* name without domain. ahd
* 29 Jul 90 Only load host table based on first six characters
* of host name. ahd
*
*/
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "lib.h"
#include "hlib.h"
#include "hostable.h"
#include "security.h"
currentfile();
static struct HostTable *hosts = NULL;
static size_t HostElements = 0;
static size_t loadhost( void );
static int hostcmp( const void *a , const void *b );
static size_t localdomainl; /* Length of localdomain */
/*--------------------------------------------------------------------*/
/* c h e c k n a m e */
/* */
/* Perform a search for a single host name */
/* */
/* Rewritten for release 1.10a. The old release had */
/* most of the same logic, but nested it inside the search */
/* loop; adding new cases (specifically, the wildcard domain */
/* search) was difficult. This version is slower because it */
/* makes multiple passes through the host table, but this */
/* isn't really performance code for a small (under 100 hosts) */
/* table. ahd 26 April 1991 */
/* */
/* Note because we save the arguments and use a static variable */
/* to save the result of searches, this function is not */
/* recursive! */
/*--------------------------------------------------------------------*/
struct HostTable *checkname(const char *name)
{
char hostname[MAXADDR]; /* Local copy of name to process */
char *period; /* Pointer "." in hostname */
size_t namel; /* Length of the name input */
size_t column; /* Length of the name input */
static char savename[MAXADDR] = "";
/* Saved copy of name to make function
reducible */
static struct HostTable *hostz;
/*--------------------------------------------------------------------*/
/* Validate the argument */
/*--------------------------------------------------------------------*/
if ((name == NULL) || ((namel = strlen(name)) == 0))
{
printmsg(0,"checkname: Invalid (missing) hostname passed");
panic();
return NULL; /* Never executed */
}
/*--------------------------------------------------------------------*/
/* If same argument as last time, return same result; otherwise */
/* save input for next pass */
/*--------------------------------------------------------------------*/
if (equali(name, savename))
return hostz;
strcpy( savename, name); /* Save for next pass */
/*--------------------------------------------------------------------*/
/* Search for the full name */
/*--------------------------------------------------------------------*/
if ((hostz = searchname(name, MAXADDR)) != BADHOST)
return hostz;
/*--------------------------------------------------------------------*/
/* If the name already has the local domain attached, search for */
/* the host name without the domain. */
/*--------------------------------------------------------------------*/
column = namel - localdomainl;
if ((namel > localdomainl) && equali(E_localdomain, &name[column]) &&
(name[ column - 1] == '.'))
{
if ((hostz = searchname(name,column-1 )) != BADHOST)
return hostz;
} /* if */
/*--------------------------------------------------------------------*/
/* If the name already has the UUCP domain attached, search for */
/* the host name without the domain. */
/*--------------------------------------------------------------------*/
column = namel - 5;
if ((column > 0) && equali(".UUCP", &name[column]))
{
if ((hostz = searchname(name, column )) != BADHOST)
return hostz;
} /* if */
/*--------------------------------------------------------------------*/
/* Search for the name in the local domain */
/*--------------------------------------------------------------------*/
if ((namel + localdomainl + 2) < MAXADDR)
{
sprintf(hostname,"%s.%s",name,E_localdomain);
if ((hostz = searchname(hostname, MAXADDR)) != BADHOST)
return hostz;
} /* if */
/*--------------------------------------------------------------------*/
/* If a simple name and not found, return search for truncated */
/* UNIX name. */
/*--------------------------------------------------------------------*/
if ( strchr(name,'.') == NULL )
return checkreal( name );
/*--------------------------------------------------------------------*/
/* Perform a wildcard domain name search */
/*--------------------------------------------------------------------*/
period = (char *) name; /* Begin at front of name */
while( period != NULL )
{
sprintf( hostname,(*period == '.') ? "*%s" : "*.%s",period);
/* We add the missing